{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/root/anaconda3/envs/cyrofold/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "from utils import get_coord_from_pdb\n",
    "from inference import load_model, preprocess_data, get_coord_from_pdb, infer_structure, save_protein"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# required: density map path, with xxx.mrc and xxx.json\n",
    "density_map_path = 'examples/density_map'\n",
    "# optional: pdb_path, to evaluate the output structure\n",
    "pdb_path = 'examples/5uz7.pdb'\n",
    "\n",
    "# basic arguments\n",
    "model_path = 'pretrained_model/checkpoint.pt'\n",
    "output_dir = 'results/'\n",
    "device = 'cuda'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preprocessing data...\n",
      "Preprocessing finished!\n"
     ]
    }
   ],
   "source": [
    "model = load_model(model_path, device)\n",
    "maps, seq, chain_encoding = preprocess_data(density_map_path, device)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "coords = None\n",
    "if pdb_path:\n",
    "    coords = get_coord_from_pdb(pdb_path)\n",
    "    coords = torch.from_numpy(coords).to(device)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "RMSD: 0.3273\n"
     ]
    }
   ],
   "source": [
    "preds, seqs, chain_encodings = infer_structure(model, maps, seq, chain_encoding, coords)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Protein structure saved to results/output.pdb\n"
     ]
    }
   ],
   "source": [
    "save_protein(preds, seqs, chain_encodings, output_dir)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "cyrofold",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
